﻿namespace SsisLdapSource.DirectoryServicesProtocolsExtensions
{
    public static class ConnectivityValidator
    {
        public static void TestConnectivity(this System.DirectoryServices.Protocols.LdapConnection ldapConnection)
        {
            IsHostOrDomainBindable(ldapConnection);
            ldapConnection.GetSubschemaSubentryDN();

            ldapConnection.GetAttributeMetaData(
                "cn",
                new LdapMetaMapFactory(
                    new LdapMetaMapFactoryInitializationValues(
                        new GuidEncodedAttributeGroup(),
                        new SidEncodedAttributeGroup(),
                        new Int64DateTimeEncodedAttributeGroup(),
                        new StringEncodedIntAttributeGroup(),
                        new AttributesWhichMayRequireExpansionGroup()
                    )));
        }

        public static void IsHostOrDomainBindable(
            this System.DirectoryServices.Protocols.LdapConnection ldapConnection)
        {
            ldapConnection.Bind();
        }
    }
}
